package com.reshare.controller;

import com.reshare.base.BaseController;
import com.reshare.base.ResultInfo;
import com.reshare.bean.Category;
import com.reshare.bean.User;
import com.reshare.query.RoleQuery;
import com.reshare.service.GoodsCategoryService;
import com.reshare.service.UserService;
import com.reshare.utils.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

@Controller
@RequestMapping("goods_category")
public class GoodsCategoryController extends BaseController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @Resource
    private UserService userService;

    @RequestMapping("index")
    public  String index(){return  "goodscategory/goods_category";}


    @RequestMapping("list")
    @ResponseBody
    public Map<String, Object> findCategory() {
        //根据条件查询角色
        Map<String, Object> map = goodsCategoryService.findAllCategory();
        //map--json
        return map;
    }

    @RequestMapping("addOrUpdateDialog")
    public String addOrUpdate(Integer id, Model model){
        if(id!=null){
            Category category=goodsCategoryService.selectByPrimaryKey(id);
            model.addAttribute("category",category);
        }
        return  "goodscategory/add_update";
    }



    @RequestMapping("save")
    @ResponseBody
    public ResultInfo save(Category category) {
        //调用方法
        System.out.println(category);
        goodsCategoryService.addCategory(category);
        return success("分类名添加成功");
    }

    @RequestMapping("update")
    @ResponseBody
    public ResultInfo update(Category category) {
        goodsCategoryService.changeCategory(category);
        return success("分类名修改成功了");
    }

    @RequestMapping("delete")
    @ResponseBody
    public ResultInfo del(Integer id) {
        System.out.println(id);
        goodsCategoryService.removCategoryById(id);
        return success("分类删除成功了");
    }


}
